package lyl.twopointer;

public class TwoSumEx {
    //arr已排好序
    //找到arr中和为target的两个数的下标
    public int[] twoSum(int[] arr,int target){
        int[] result = new int[2];
        result[1] = result[0] = -1;
        if(arr == null || arr.length == 0){
            return arr;
        }
        int start = 0;
        int end = arr.length - 1;
        while(start < end){
            if(arr[start] + arr[end] == target){
                result[0] = start;
                result[1] = end;
                break;
            }
            else if(arr[start] + arr[end] < target){//小了左边的移动
                start++;
            }
            else if(arr[start] + arr[end] >target){//大了右边的移动
                end--;
            }
        }
        return result;

    }
}
